package cn.edu.neusoft.wuguangsheng.flowerimpression.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.activity.BaiKeInfoActivity;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.BaiKeBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.service.Service;

public class BaiKeAdapter extends BaseAdapter<BaiKeBean> {

    public BaiKeAdapter(Context context, List<BaiKeBean> items, int layoutResourse) {
        super(context, items, layoutResourse);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView= LayoutInflater.from(context).inflate(layoutResourse,parent,false);
        BaiKeViewHolder viewHolder = new BaiKeViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        BaiKeViewHolder viewHolder=(BaiKeViewHolder) holder;
        BaiKeBean baiKeBean=items.get(position);
        final String name = baiKeBean.getEnc_name();
        final String bieming = baiKeBean.getEnc_alias();
        final String huaqi = baiKeBean.getEnc_florescence();
        final String img = Service.BASE_URL+"flower_impression/public/uploads/"+baiKeBean.getEnc_photo();
        final String enc_id = baiKeBean.getEnc_id();

       // String img = Service.BASE_URL+"flower_impression/public/uploads/"+answerBean.getUser_photo();
        Picasso.with(context).load(img).into(viewHolder.baikeitem_img);

        viewHolder.baikeitem_name.setText(name);
        viewHolder.baikeitem_bieming.setText(bieming);
        viewHolder.baikeitem_huaqi.setText(huaqi);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, BaiKeInfoActivity.class);
                intent.putExtra("enc_id",enc_id);
                context.startActivity(intent);
            }
        });
    }
}
